import numpy as np
import pandas as pd
from sklearn.model_selection import train_test_split

def load_data(config):
    # Load and preprocess dataset
    ratings = pd.read_csv(config.data_path + "ratings.csv")
    
    # Create user-item matrix
    user_ids = ratings['user_id'].unique()
    item_ids = ratings['item_id'].unique()
    
    # Generate popularity bias
    item_popularity = ratings['item_id'].value_counts().to_dict()
    
    # Split dataset
    train_data, test_data = train_test_split(ratings, test_size=0.2)
    
    return {
        'train': train_data,
        'test': test_data,
        'popularity': item_popularity,
        'n_users': len(user_ids),
        'n_items': len(item_ids)
    }
